package in.muton.edushare.pages.curricula;

import in.muton.edushare.EduShareSession;

import java.util.Comparator;

import org.apache.wicket.model.IModel;

import com.edushare.common.dao.CoursesDAO;
import com.edushare.common.vo.Courses;
import com.edushare.common.vo.Departments;

public class CourseComparator implements Comparator<IModel<Courses>> {
	public int compare(IModel<Courses> arg0, IModel<Courses> arg1) {
		CoursesDAO cdao = new CoursesDAO(EduShareSession.get().getSessionORMInterface());
		Departments d1 = cdao.getParentDept(arg0.getObject());
		Departments d2 = cdao.getParentDept(arg1.getObject());
		if(d1 == d2)
			return arg0.getObject().getCourseName().compareTo(arg1.getObject().getCourseName());
		else
			return d1.getDeptName().compareTo(d2.getDeptName());
	}
}
